home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS03.ADF / C / 6bitcolor.c < prev    next >
C/C++ Source or Header  |  1986-04-02  |  10KB  |  284 lines

  1. /* how to get 64 colors without tricks, text and source */
  2.  
  3. /* warning: this extra-half-bright mode works only on revision 6 of the 
  4.     Daphne chip, in Amigas made after first quarter '86 
  5. */
  6.  
  7. #ifdef FOOIE
  8.  
  9. From bobp@amiga.UUCP (Robert S. Pariseau) Sat Nov  9 04:15:42 1985
  10. Path: gumby!uwvax!seismo!caip!topaz!packard!ihnp1!ihnp4!nsc
  11.         !pyramid!amiga!bobp
  12. From: bobp@amiga.UUCP (Robert S. Pariseau)
  13. Date: 9 Nov 85 10:15:42 GMT
  14.  
  15.  
  16. TITLE:  Fun With 6 Bit Planes (SOURCE)
  17.  
  18. There are lots of fun things you can do in 6 bit planes on the Amiga, 
  19. including Hold and Modify color displays and dual-playfield mode with two 
  20. separately scroll-able, completely independent, 8 color playfields with 
  21. overlay and transparency.
  22.  
  23. But tonight I'm going to discuss something you don't already know about your 
  24. Amiga -- even if you've read all the tech manuals cover to cover.
  25.  
  26. The specs for the Amiga say that in a completely static, low-resolution 
  27. display, with nothing fancy going on (like Hold and Modify), you can display 
  28. up to 32 colors simultaneously out of a pallette of 4096.
  29.  
  30. Well not quite.
  31.  
  32. You can actually display up to 64 distinct colors out of that pallette of 
  33. 4096!  Yes, an unlimited choice of any of 64 colors at each pixel in the 
  34. screen!
  35.  
  36. Have I got your attention?
  37.  
  38. Welcome to Extra-Half-Brite mode.
  39.  
  40. The Amiga display hardware automatically enters Extra-Half-Brite mode 
  41. whenever you select a 6 plane display (which must be low res due to the 
  42. hardware) and have NOT selected either Hold and Modify or Dual Playfield mode.
  43.  
  44. The graphics kernel software further enforces the rule that you must set the 
  45. EXTRA_HALFBRITE flag in the ViewModes for the ViewPort (Screen in Intution 
  46. lingo) or it will automatically trim your screen down to 5 planes.  This is 
  47. done both for backward compatability and to insure support in future Amiga 
  48. architectures.
  49.  
  50. Consider the playfield data bits for a given pixel.  The bits from the first 
  51. five planes form a color register selector for that pixel, allowing you to 
  52. choose among the 32 color registers in the Amiga.  The bit from the sixth 
  53. plane is interpreted as follows: 
  54.  
  55. 0 -- Use the color in the selected color register just as specified.
  56.  
  57. 1 -- Take the color in the selected color register, shift each of
  58.        its R, G, and B components right one bit, and use the new
  59.        color value thus formed.
  60.  
  61. The net result is as if you had 64 color registers where the colors in the 
  62. top 32 were "half-intensity" counterparts of the colors in the bottom 32!
  63.  
  64. Of course, that means there is a dependency between the choice of colors in 
  65. the 32 real registers and the resulting colors in the 32 psuedo-registers.  
  66. Nevertheless, I assert we have as much right to claim 64 colors on screen as 
  67. IBM has to claim 16 colors from a monitor that is physically capable of 
  68. producing only 8 colors at 2 intensities!  At least we can select our 32 
  69. colors out of a pallatte of 4096!
  70.  
  71. Note also that, since fractional color components have no meaning in the 
  72. hardware, there are several distinct real colors that produce the same extra 
  73. color.  
  74.  
  75. For instance (in hex): 
  76. 888 --> 444,    988 --> 444,   898 --> 444,   999 --> 444,  etc.
  77.  
  78. Despite all this quibbling, with a little thought it's easy to see how you 
  79. can choose a set of 32 real colors to make sure all 64 real plus extra colors 
  80. are distinct.  And they are every-pixel-addressable!
  81.  
  82. Why have we kept this little jewel a secret?  No, it's not that we were 
  83. planning to lull the competition into complacency and then spring an instant 
  84. double of the Amiga's color capacity on them.
  85.  
  86. Actually, the rev of the custom chips in which this worked was the last rev 
  87. before we went into production.  Thus the info was too late to make it into 
  88. the current version of the Amiga Hardware Manual.
  89.  
  90. Some caveats.  Although ALL the consumer machines have the necessary chip 
  91. rev, there are some older developer's machines out there which can't do this 
  92. trick.  BEWARE!  Some of the store demo units come out of that older 
  93. developer's stock and won't contain the Extra-Half-Brite hardware.  Note that 
  94. you can't hurt anything by running such a program on an older machine -- the 
  95. values in the 6th bit plane will simply be ignored.
  96.  
  97. Also the V1.0 printer device will not correctly handle this trick for color 
  98. printing -- it works fine in V1.1.
  99.  
  100. The sample program below shows Extra-Half-Brite mode in operation.
  101.  
  102. -------------------------Program Notes
  103.  
  104. The Extra program will compile and link cleanly using the native Amiga 
  105. Lattice C tools on the standard V1.0 C disk.  The Make script in the examples 
  106. directory will do all the work for you.
  107.  
  108. I suggest you copy your source file into ram disk, cd over to your C 
  109. development disk, and type
  110.  
  111.   1> execute Make ram:Extra    [assumes you are where Make is]
  112.  
  113. Afterwards, copy the resulting Extra program back out of ram: to someplace 
  114. safe from power failures.
  115.  
  116. The program itself is pretty straightforward.  It opens a 6 plane low res 
  117. custom screen and then opens a window in that screen. 64 color patches are 
  118. then drawn into that window with color register usage increasing left to 
  119. right then top to bottom from 0 to 63.  For simplicity, this program uses the 
  120. default color pallette supplied with the new screen.
  121.  
  122. Due to the EXTRA_HALFBRITE special ViewMode in the screen definition, the 
  123. bottom 4 rows of color should be the half intensity counterparts of the 
  124. corresponding patches in the top 4 rows.
  125.  
  126. The program waits for a CLOSEWINDOW message from Intution, then cleans up and 
  127. goes away.
  128.  
  129. -------------------------Program Source Follows:
  130.  
  131. #endif FOOIE
  132.  
  133. /***********************************************************************
  134.  *  Extra -- Program to demonstrate Extra-Half-Brite graphics display
  135.  *           mode on the Amiga.
  136.  *
  137.  *  Dale Luck    -- October, 1985
  138.  *  Bob Pariseau -- November 8, 1985  (Editorial changes)
  139.  *
  140.  **********************************************************************/
  141.  
  142. #include <exec/types.h>
  143. #include <exec/tasks.h>
  144. #include <exec/libraries.h>
  145. #include <exec/devices.h>
  146. #include <devices/keymap.h>
  147. #include <graphics/copper.h>
  148. #include <graphics/display.h>
  149. #include <graphics/gfxbase.h>
  150. #include <graphics/text.h>
  151. #include <graphics/view.h>
  152. #include <graphics/gels.h>
  153. #include <graphics/regions.h>
  154. #include <hardware/blit.h>
  155. #include <intuition/intuition.h>
  156. #include <intuition/intuitionbase.h>
  157.  
  158.  
  159. struct   GfxBase        *GfxBase;         /* Export library base pointers */
  160. struct   IntuitionBase  *IntuitionBase;
  161.  
  162. struct   Screen   *colscreen;             /* Pointers to new screen and   */
  163. struct   Window   *wndo;                  /* window.                      */
  164.  
  165. struct   NewScreen newscreen;             /* OpenX() arguments for new    */
  166. struct   NewWindow newwindow;             /* screen and window.           */
  167.  
  168. struct   TextAttr Font =
  169. {
  170.    "topaz.font",            /* Use standard system font */
  171.    8,
  172.    FS_NORMAL,
  173.    FPF_ROMFONT,
  174. };
  175.  
  176. struct IntuiMessage *message;
  177.  
  178.  
  179.  
  180. main()
  181. {
  182.    if ((IntuitionBase = (struct  IntuitionBase *)OpenLibrary("intuition.library", 0)) == 0)
  183.    {
  184.       printf("WOT !  No Intuition ???\n");
  185.       exit();
  186.    }
  187.  
  188.    if ((GfxBase = (struct   GfxBase *)OpenLibrary("graphics.library", 0)) == 0)
  189.    {
  190.       printf("Oh ! No Graphics??\n");
  191.       CloseLibrary(IntuitionBase);
  192.       exit();
  193.    }
  194.  
  195. /* values for new screen */
  196.    newscreen.LeftEdge       = 0;
  197.    newscreen.TopEdge        = 0;
  198.    newscreen.Width          = 320;
  199.    newscreen.Height         = 200;
  200.    newscreen.Depth          = 6;
  201.    newscreen.DetailPen      = 0;
  202.    newscreen.BlockPen       = 1;
  203.    newscreen.ViewModes      = EXTRA_HALFBRITE;
  204.    newscreen.Type           = CUSTOMSCREEN;
  205.    newscreen.Font           = &Font;
  206.    newscreen.DefaultTitle   = "Six Planes Low Res";
  207.    newscreen.Gadgets        = NULL;
  208.    
  209.    colscreen = (struct Screen *)OpenScreen(&newscreen);
  210.    if (colscreen == 0)
  211.    {
  212.       printf("Screen Failed !!!!!\n");
  213.       CloseLibrary(GfxBase);
  214.       CloseLibrary(IntuitionBase);
  215.       exit();
  216.    }
  217.  
  218. /* values for new window */
  219.    newwindow.LeftEdge      = 0;
  220.    newwindow.TopEdge       = 15;
  221.    newwindow.Width         = 320;
  222.    newwindow.Height        = 185;
  223.    newwindow.DetailPen     = 0;
  224.    newwindow.BlockPen      = 1;
  225.    newwindow.Flags         = ACTIVATE | SIMPLE_REFRESH | WINDOWCLOSE;
  226.    newwindow.IDCMPFlags    = CLOSEWINDOW;
  227.    newwindow.FirstGadget   = NULL;
  228.    newwindow.CheckMark     = NULL;
  229.    newwindow.Title         = "Extra-Half-Brite Colors!";
  230.    newwindow.Screen        = colscreen;
  231.    newwindow.BitMap        = NULL;
  232.    newwindow.MinWidth      = 20;
  233.    newwindow.MinHeight     = 20;
  234.    newwindow.MaxWidth      = 320;
  235.    newwindow.MaxHeight     = 200;
  236.    newwindow.Type          = CUSTOMSCREEN;
  237.  
  238.    wndo = (struct Window *)OpenWindow(&newwindow);
  239.    if (wndo == 0)
  240.    {
  241.        printf("Window failed!!!\n"); 
  242.        CloseScreen(colscreen);
  243.        CloseLibrary(GfxBase);
  244.        CloseLibrary(IntuitionBase);
  245.        exit();
  246.    }
  247.  
  248.    setup(wndo->RPort);
  249.  
  250.    FOREVER
  251.    {
  252.       WaitPort(wndo->UserPort);
  253.       message = (struct IntuiMessage *)GetMsg(wndo->UserPort);
  254.       if(message->Class == CLOSEWINDOW)
  255.       {
  256.          ReplyMsg(message);       /* Can't reply till done using */
  257.          CloseWindow(wndo);
  258.          CloseScreen(colscreen);
  259.          CloseLibrary(GfxBase);
  260.          CloseLibrary(IntuitionBase);
  261.          exit();
  262.       }
  263.       ReplyMsg(message);
  264.    }
  265.  
  266. }
  267.  
  268. setup(rastp)
  269. struct RastPort *rastp;
  270. {
  271.    USHORT   countx;
  272.    USHORT   county;
  273.    USHORT   color;
  274.  
  275.    for (countx = 0; countx < 8; countx++)
  276.       for (county = 0; county < 8; county++)
  277.       {
  278.          color = (county<<3) + countx;
  279.          SetAPen(rastp,color);
  280.          RectFill(rastp,countx*35+10,county*20+15,countx*35+45,county*20+35);
  281.       }
  282. }
  283.  
  284.